﻿Imports System.Collections.ObjectModel

'******************************************************
'******************************************************
'Application Title: Google Widget Editor
'version: 1.0
'Date: 02-02-2008
'Requirements: win2k or later
'Author: Andrew Pye
'Author Email: StretchMasterP@googlemail.com
'License: Released under GNU GENERAL PUBLIC LICENSE v3
'ToDo:
'Changes:Added Project Templates to the frmNew
'******************************************************
'******************************************************

''' <summary>
''' New Project Form
''' </summary>
''' <remarks></remarks>
Public Class frmNew
#Region "Fields"
    Private _ProjectName As String = ""
    Private _TemplateName As String = ""
#End Region
#Region "Properties"
    Public Property ProjectName() As String
        Get
            Return _ProjectName
        End Get
        Set(ByVal value As String)
            _ProjectName = value
        End Set
    End Property
    Public Property TemplateName() As String
        Get
            Return _TemplateName
        End Get
        Set(ByVal value As String)
            _TemplateName = value
        End Set
    End Property
#End Region
#Region "Methods"
    ''' <summary>
    ''' Sets the template details
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetTemplateDetails()
        If String.IsNullOrEmpty(txtProjectName.Text) Then
            MsgBox("Please Enter A Project Name")
        Else
            Me.ProjectName = txtProjectName.Text
            If Not lstNewProjectTemplates.SelectedItems Is Nothing Then
                If lstNewProjectTemplates.SelectedItems.Count > 0 Then
                    Me.TemplateName = lstNewProjectTemplates.SelectedItems(0).Tag
                End If
            Else
                Me.TemplateName = ""
            End If
            End If
    End Sub
    ''' <summary>
    ''' Load the List
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub RefreshList()

        Dim TPath As String = My.Application.Info.DirectoryPath & "\Data\Project Templates"
        Dim files As ReadOnlyCollection(Of String)
        files = My.Computer.FileSystem.GetFiles(TPath, FileIO.SearchOption.SearchAllSubDirectories, "*.txml")
        lstNewProjectTemplates.Items.Clear()
        lstNewProjectTemplates.Items.Add("Blank", "TEMPLATE")
        For Each TItem As String In files
            Dim TFileName As String = IO.Path.GetFileNameWithoutExtension(TItem)
            Dim Tobj As ListViewItem = lstNewProjectTemplates.Items.Add(TFileName, "TEMPLATE")
            Tobj.Tag = TItem
        Next
        lstNewProjectTemplates.Items(0).Selected = True

    End Sub
#End Region
#Region "Form Events"
    Private Sub frmNew_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RefreshList()
        txtProjectName.Focus()
    End Sub
    Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click
        SetTemplateDetails()
    End Sub
    Private Sub lstNewProjectTemplates_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstNewProjectTemplates.DoubleClick
        SetTemplateDetails()
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Hide()
    End Sub
#End Region

    Private Sub lstNewProjectTemplates_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstNewProjectTemplates.SelectedIndexChanged

    End Sub
End Class